﻿using Microsoft.AspNetCore.Mvc;
using NetCore.Dtos;
using NetCore.Entities;
using NetCore.Interfaces;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;

namespace NetCore.Services
{
    /// <summary>
    /// 泛型基类AppService接口 完成所有公共接口
    /// </summary>
    /// <typeparam name="TEntity">实体类</typeparam>
    /// <typeparam name="TPrimaryKey">实体类主键类型</typeparam>
    public interface IBaseNetCoreAppService<TEntity, TPrimaryKey>
        where TEntity : BaseEntity<TPrimaryKey>
    {
        #region 实体增删改查

        /// <summary>
        /// 获取实体BaseRepository
        /// </summary>
        /// <returns></returns>
        INetCoreRepository<TEntity, TPrimaryKey> GetBaseRepository();

        /// <summary>
        /// 根据主键获取实体
        /// </summary>
        /// <param name="input">实体主键输入类</param>
        /// <returns></returns>
        [Description("根据主键获取实体")]
        TEntity Get(InputIdDto<TPrimaryKey> input);

        /// <summary>
        /// 异步添加实体
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        [Description("异步添加实体")]
        Task<TEntity> InsertAsync(TEntity entity);
        /// <summary>
        /// 批量添加实体
        /// </summary>
        /// <param name="entities">实体集</param>
        /// <returns></returns>
        [Description("批量添加实体")]
        Task<IActionResult> BulkInsertAsync(IList<TEntity> entities);

        /// <summary>
        /// 根据主键删除实体
        /// </summary>
        /// <param name="input">主键Id</param>
        /// <returns></returns>
        [Description("删除数据")]
        IActionResult Delete(InputIdDto<TPrimaryKey> input);

        /// <summary>
        /// 根据主键删除实体
        /// </summary>
        /// <param name="input">实体主键</param>
        /// <returns></returns>
        [Description("根据主键删除实体")]
        Task<IActionResult> DeleteAsync(InputIdDto<TPrimaryKey> input);

        /// <summary>
        /// 批量删除实体
        /// </summary>
        /// <param name="entities">实体集</param>
        /// <returns></returns>
        [Description("批量删除数据")]
        Task<IActionResult> BulkDeleteEntityAsync(IList<TEntity> entities);

        /// <summary>
        /// 批量删除实体
        /// </summary>
        /// <param name="ids">实体主键集合</param>
        /// <returns></returns>
        [Description("批量删除实体")]
        Task<IActionResult> BulkDeleteAsync(IList<TPrimaryKey> ids);

        #endregion


        #region 重复性验证 重新设计

        /// <summary>
        /// 单字段重复性验证
        /// </summary>
        /// <param name="field">单个字段选项</param>
        /// <returns></returns>
        [HttpPost]
        IActionResult CheckFieldUnique(FieldCheckOptionDto<TPrimaryKey> field);

        /// <summary>
        /// 多字段重复性验证，dxGrid在新建/编辑数据时 时时验证
        /// </summary>
        /// <param name="fields">多字段dto选项</param>
        /// <returns></returns>
        [HttpPost]
        IActionResult CheckFieldsUnique(List<FieldCheckOptionDto<TPrimaryKey>> fields);

        #endregion
    }
    /// <summary>
    /// 基类AppService接口
    /// </summary>
    /// <typeparam name="TEntity">实体类</typeparam>
    public interface IBaseNetCoreAppService<TEntity> : IBaseNetCoreAppService<TEntity, int>
        where TEntity : BaseEntity
    {
    }

}
